package com.example.books;

import android.content.SharedPreferences;
import android.os.Bundle;

import com.example.books.ui.dashboard.DashboardViewModel;
import com.example.books.ui.home.HomeViewModel;
import com.example.books.ui.notifications.NotificationsFragment;
import com.example.books.ui.notifications.NotificationsViewModel;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProviders;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

public class UserActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        BottomNavigationView navView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(navView, navController);
        setViewModeladdData();
    }

    private void setViewModeladdData() {
        NotificationsViewModel notificationsViewModel = ViewModelProviders.of(this).get(NotificationsViewModel.class);
        HomeViewModel homeViewModel = ViewModelProviders.of(this).get(HomeViewModel.class);
        DashboardViewModel dashboardViewModel = ViewModelProviders.of(this).get(DashboardViewModel.class);
        SharedPreferences id = getSharedPreferences("id",UserActivity.MODE_PRIVATE);
        int sid = id.getInt("sid", 0);
        String sname = id.getString("sname", "");
        notificationsViewModel.setSid(sid);
        notificationsViewModel.setSname(sname);
        homeViewModel.setBid(sid);
        dashboardViewModel.setSid(sid);
    }

}
